package work20241226;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zdl
 * @date 2024/12/26
 */
public class Demo18 {
    public static void main(String[] args) {
        //18. 创建一个可缓存线程池，提交10个任务，每个任务打印当前线程的名称，并等待所有任务执行完毕。
        ExecutorService pool = Executors.newCachedThreadPool();
        for (int i = 0; i < 10; i++) {
            pool.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println("线程名儿:"+Thread.currentThread().getName()); //线程1-10
                }
            });
        }
    }
}
